// pages/myself/addposition/addposition.js
const app = getApp()
var queryUrl = app.globalData.queryUrl;
var start;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wages: ["面议","3000以下", "3000-3999", "4000-4999", "5000-5999", "6000-6999", "7000-7999", "8000-8999", "9000-9999", "10000-14999", "15000-19999", "20000-24999", "25000-29999", "30000-34999", "35000-39999", "40000-49999", "50000-69999", "70000-99999", "100000及以上"],
    years: ["不限", "无经验", "1-3年", "3-5年", "5-10年", "10年以上"],
    edu: ["不限", "大专", "本科", "硕士", "博士"],
    shopId:'',
    openId:'',
    postion: '',
    experience: 0,
    salary: 0,
    education: 0,
    requir: '',
    jobRequire: '',
    welfare:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    // var shopId = options.shopId
    // that.setData({ shopId: shopId })
    try {
      var openId = wx.getStorageSync('openId')
    } catch (e) { }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //薪资
  bindXzChange: function (e) {
    console.log(e);
    this.setData({ salary: e.detail.value })
  },
  //工作经验
  yearsChange: function (e) {
    this.setData({
      experience: e.detail.value
    })
  },
  //学历
  eduChange: function (e) {
    this.setData({
      education: e.detail.value
    })
  },
  //福利待遇
  welfare: function (e) {
    this.setData({
      welfare: e.detail.value
    })
  },
  // 获取岗位名称
  positName: function (e) {
    this.setData({
      postion: e.detail.value,
    })
  },
  postRequire: function (e) {
    this.setData({
      requir: e.detail.value,
    })
    // console.log(e.detail.value)
  },
  jobRequire: function (e) {
    this.setData({
      jobRequire: e.detail.value
    })
  },
  welfare: function (e) {
    this.setData({
      welfare: e.detail.value
    })
  },
  // 完成按钮
  complete: function (e) {
    var that = this;
    var postion = that.data.postion;
    var experience = that.data.years[that.data.experience]
    var salary = that.data.wages[that.data.salary]
    var education = that.data.edu[that.data.education]
    var requir = that.data.requir;
    var jobRequire = that.data.jobRequire;
    var welfare = that.data.welfare;
    if (postion == '') {
      wx.showToast({
        title: '岗位名称不能为空',
        icon: 'none'
      })
      return false;
    }
    if (requir == '') {
      wx.showToast({
        title: '请输入岗位要求',
        icon: 'none'
      })
      return false;
    }
    if (jobRequire == '') {
      wx.showToast({
        title: '请输入任职要求',
        icon: 'none'
      })
      return false;
    }
    if (welfare == '') {
      wx.showToast({
        title: '请输入福利待遇',
        icon: 'none'
      })
      return false;
    }
    wx.showLoading({
      title: '加载中'
    })
    wx.request({
      url: queryUrl + 'recruit/register',
      data: {
        // shopId:that.data.shopId,
        shopId: 2,
        opendId: that.data.openId,
        postion: postion,
        experience:experience,
        salary: salary,
        education: education,
        jobRequire: jobRequire,
        requir: requir,
        welfare: welfare
      },
      method: 'post',
      success: function (res) {
        console.log(res)
        if (res.data.status == 1){
          wx.showToast({
            title: '添加成功',
            icon: 'none'
          });
        }
      }
    })
  },
  
})